package users.christy.app;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import users.christy.beans.Config;
import users.christy.beans.DatabaseParameters;

public class MainChristyApp {
	public static void main(String[] args) {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("users/christy/christy.main.xml");
		
		//Register a shutdown hook
		context.registerShutdownHook();
		
		final Config config = context.getBean("config", Config.class);
		
		System.out.println(
				printAllFields(config)
		);
		
		config.setMaxCacheSize(9999);
		
		System.out.println(
				printAllFields(config)
		);
		
		Config anotherConfig = context.getBean("config", Config.class);

		System.out.println(
			printAllFields(anotherConfig)
		);		

	}

	private static String printAllFields(Config config) {
		final DatabaseParameters dbParms = config.getDbParams();
		return "Username: " + dbParms.getUsername() + "; Password: " + dbParms.getPassword()
			+ "; Connection: " + dbParms.getConnectionString() + "; Date Format: " 
				+ config.getDateFormat() + "; Max Cache Size: " + config.getMaxCacheSize()
				+ "; Java Home: " + config.getJavaHome();
	}	
}
